﻿
namespace BusinessApplication.Web.Services
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
    using BusinessApplication.Web.Model;


    // Implements application logic using the DatabaseEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    [EnableClientAccess()]
    public class MapService : DomainService
    {

        public IQueryable<LocationItem> GetLocations()
        {
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DatabaseEntities"].ConnectionString.ToString();

            var data = new Model.DatabaseEntities(connectionString);
            var list = new List<LocationItem>();

            if (data != null)
            {
                foreach (var entry in data.tbl_locations)
                {

                    list.Add(new LocationItem
                    {
                        Id = entry.locations_id.ToString(),
                        Lat = entry.lat,
                        Lng = entry.lng,
                        Address = entry.address,
                        Title = entry.tbl_products.products_name
                    });

                }
            }

            return list.AsQueryable();
        }

    }
}


